﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PurchaseHistoryListCtrl.ascx.cs" Inherits="WebUI.Controls.PurchaseHistoryListCtrl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<script type="text/javascript">
var <%=ClientID %>clickOnCheckbox;
var <%=ClientID %>selectedRow = null;       
var <%=ClientID %>selectedCheckbox = null; 
var <%=ClientID %>selectedID = null; 
var <%=ClientID %>selectedClass = null; 

function resetGridSelection<%=ClientID %>(){
    <%=ClientID %>selectedRow = null;   
    if(<%=ClientID %>selectedCheckbox != null)
        <%=ClientID %>selectedCheckbox.checked = false;          
    <%=ClientID %>selectedCheckbox = null; 
    <%=ClientID %>selectedID = null; 
    <%=ClientID %>selectedClass = null; 
}

function clickOnCheckBox<%=ClientID %>(cb){
    <%=ClientID %>clickOnCheckbox = true;
}

function onItemClick<%=ClientID %>(sender)
{
    if(<%=ClientID %>clickOnCheckbox){
        <%=ClientID %>clickOnCheckbox = false;
        return;
    }
    
    if(<%=ClientID %>selectedRow != null){
        if(<%=ClientID %>selectedRow.className)
            <%=ClientID %>selectedRow.className = <%=ClientID %>selectedClass;
        else
            <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;
    }
    
    if(sender.className){
        <%=ClientID %>selectedClass = sender.className;
        sender.className = "CustomGridSelectedItem";
    }
    else{
        <%=ClientID %>selectedClass = sender.getAttribute("class");
        sender.setAttribute("class", "CustomGridSelectedItem");
    }
    <%=ClientID %>selectedRow = sender;
    
    var inputs = sender.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
            <%=ClientID %>selectedCheckbox = inputs[i];
            inputs[i].checked = true;
            break;
        }
    }
    
    <%=ClientID %>selectedID = <%=ClientID %>selectedRow.getAttribute("ItemID");
}

function selectAll<%=ClientID %>(cbAll){
    var grid = document.getElementById("<%=grid.ClientID %>");
    var inputs = grid.getElementsByTagName("input");
    for(var i = 0; i < inputs.length; i++){
        if(inputs[i].type == "checkbox"){
            inputs[i].checked = cbAll.checked;
        }
    }
}

function getSelectedItemID<%=ClientID %>()
{
    return <%=ClientID %>selectedID;
}

function showPrintDlg(key) {
    var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
}

//function onInvoiceNo_click(lnk)
//{

//    hidInvoiceID.value = lnk.getAttribute('ItemID');
//}

function onPurchaseOrderNo_click(lnk){
    var hidInvoiceID = document.getElementById("<%= hidInvoiceID.ClientID %>");     
    hidInvoiceID.value = lnk.getAttribute('ItemID');
}
</script>

<%--start modify here--%>



<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None" class="customGrid" ShowFooter="true"
AutoGenerateColumns="false" EmptyDataText="No record to display" ItemStyle-Wrap="true" CellPadding="1" CellSpacing="1"
OnSortCommand="grid_OnSortCommand" OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound"
OnPageIndexChanged="grid_OnPageIndexChanged" AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
<PagerStyle Mode="NumericPages" PageButtonCount="10"   />
<Columns>
    <asp:TemplateColumn ItemStyle-Width="30px" HeaderStyle-Width="30px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
        <HeaderTemplate><asp:CheckBox ID="cbSelectAll" runat="server" ItemID='<%# Eval("ID") %>'/></HeaderTemplate>
        <ItemTemplate>
            <asp:CheckBox ID="cbSelect" runat="server" />
        </ItemTemplate>
    </asp:TemplateColumn>
    <%--start modify here--%>
    <%--<asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="250px" DataField="CreatedDate" SortExpression="CreatedDate" HeaderText="Date" Visible="true"></asp:BoundColumn>--%>
    <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" SortExpression="CreatedDate" HeaderText="Date" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblDate" runat="server" Text='<%# ((DateTime)Eval("CreatedDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>

    <asp:TemplateColumn HeaderText="Purchase#" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
        <ItemTemplate>
            <asp:LinkButton ID="lnkPurchaseOrderNo" runat="server" Text='<%# Eval("PurchaseOrderNo") %>' OnClientClick='onPurchaseOrderNo_click(this); return true;' OnClick="btnPrint_OnClick" ItemID='<%# Eval("ID") %>'></asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="100px" DataField="InvoiceNo" SortExpression="InvoiceNo" HeaderText="Invoice#" Visible="true"></asp:BoundColumn>
    <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="250px" DataField="SupplierName" SortExpression="SupplierName" HeaderText="Supplier" Visible="true"></asp:BoundColumn>
    <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="60px" DataField="TotalAmount" SortExpression="TotalAmount" HeaderText="Total" Visible="true"></asp:BoundColumn>
    <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="60px" DataField="PaidAmount" SortExpression="PaidAmount" HeaderText="Paid" Visible="true"></asp:BoundColumn>
    <asp:TemplateColumn  SortExpression="Balance"  HeaderText="Balance" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Right"
        HeaderStyle-HorizontalAlign="Left">
        <ItemTemplate>
            <asp:Label ID="lblBalance" runat="server" Text='<%# Eval("Balance") %>'></asp:Label>
            <asp:TextBox ID="txtBalance" Width="60px" runat="server" Text='<%# Eval("Balance").ToString() %>'></asp:TextBox>
            <cc1:FilteredTextBoxExtender FilterType="Numbers, Custom" ValidChars="." TargetControlID="txtBalance"
                ID="FilteredTextBoxExtenderSpecialPrice" runat="server">
            </cc1:FilteredTextBoxExtender>
        </ItemTemplate>
    </asp:TemplateColumn>
</Columns>
</asp:DataGrid>

<asp:HiddenField ID="hidInvoiceID" runat="server" />
<asp:HiddenField ID="hidSelectedID" runat="server" />